##################################
###### START REP FILES HERE ######
##################################

rm(list = ls())

# load packages; install simcf if necessary

if(!require(simcf)){
  install.packages("http://faculty.washington.edu/cadolph/software/simcf_0.2.17.tgz",
                    repos = NULL)
  library(simcf)
} else { 
  library(simcf)
}

pacman::p_load("tidyverse",
               "broom",
               "stargazer",
               "xtable",
               "nnet",
               "glm.predict",
               "sandwich",
               "sfsmisc",
               "ggthemes",
               "gridExtra",
               "systemfit",
               "broom",
               "weights",
               "janitor",
               "texreg",
               "kableExtra",
               "survey")

# function to reproduce table and plot output
reproduce <- function () {
  # verify (or create) necessary file structure for output
  if(!file.exists("./plots")) dir.create("./plots")
  if(!file.exists("./tables")) dir.create("./tables")
  
  # NOTE --  data_exp_2.R must be run before sim_cf_preds.R to load necessary objects
  
  # to generate
  # Tables 1, B.1, B.2, B.3, B.4, E.7, E.8
  # Figures 4, 5, B.3, F.6
  source("code/data_exp_2.R") 
  
  # to generate
  # Figures 4, E.4
  source("code/sim_cf_preds.R") # generate predictions and plots
  
  # to generate
  # Figure F.5 and Tables F.9 and 
  source("code/weighted_analysis.R")
  
  # code for national survey data and plots
  # this generates Figure A.2
  source("code/national_svy_city.R")
  
  # run CEM mentioned in fn. 18
  source("code/matching_april.R")
}

reproduce()
